<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>考勤管理</el-breadcrumb-item>
      <el-breadcrumb-item>名单查看</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card class="box-card">
      <!-- 搜索与添加区域 -->
      <el-row :gutter="20">
        <!-- <el-col :span="9">
          <el-input
            placeholder="请输入内容"
            class="input-with-select"
            v-model="queryInfo.query"
            clearable
            @clear="getUserCheckList"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="getUserCheckList"
            ></el-button>
          </el-input>
        </el-col> -->
        <!-- <el-col :span="4">
          <el-button type="primary" @click="dialogVisible = true"
            >添加用户</el-button
          >
        </el-col> -->
        <el-col :span="4">
          <el-button type="primary" @click="exportFile">导出名单</el-button>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table
        :data="userCheckList"
        stripe
        border
        ref="multipleTable"
        height="500"
      >
        <!-- 多选栏 -->
        <el-table-column type="index"> </el-table-column>
        <el-table-column prop="userVo.userName" label="姓名"> </el-table-column>
        <el-table-column prop="userVo.userIdentity" label="政治面貌">
          <template slot-scope="scope">
            <el-tag type="danger">
              {{ scope.row.userVo.userIdentity }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="checkTime" label="签到时间"> </el-table-column>
        <el-table-column label="签到情况">{{ "已签到" }} </el-table-column>
        <!-- <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="showEditDialog(scope.row)"
              >修改</el-button
            >
          </template>
        </el-table-column> -->
      </el-table>
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="queryInfo.pagenum"
        :page-sizes="[1, 2, 5, 10, 15]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination> -->
    </el-card>
    <!-- 添加修改成绩对话框 -->
    <el-dialog
      title="修改成绩"
      :visible.sync="editVisible"
      @close="closeEditForm"
    >
      <el-form
        :model="editForm"
        ref="editForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="成绩" prop="">
          <el-input v-model="editForm.score"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editVisible = false">取 消</el-button>
        <el-button type="primary" @click="editScore">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import exportCheckFile from "./exportCheckFile.js";
export default {
  data() {
    return {
      // 获取用户列表对象
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 15
      },
      // 用户列表
      userCheckList: [],
      // 用户修改信息列表
      userEditList: [],
      total: 0,
      dialogVisible: false,
      editVisible: false, //修改用户信息对话框显示与隐藏
      // 添加用户的表单数据
      addForm: {
        username: "",
        password: "",
        email: "",
        mobile: ""
      },
      editForm: {
        score: ""
      },
      changeForm: {},
      changeVisible: false,
      // 用户信息
      userinfo: {},
      selectRole: "",
      roleList: [],
      // 用户删除列表
      userDeleteIdList: [],
      // 当前选中
      value: "",
      // 签到编号
      signId: "",
      // 小测编号
      quizId: "",
      // 导出文件名称
      fileName: ""
    };
  },
  created() {
    this.value = window.sessionStorage.getItem("value");
    this.signId = window.sessionStorage.getItem("signId");
    this.fileName = window.sessionStorage.getItem("signTitle");
    this.getUserCheckList();
  },
  methods: {
    //导出Excel文件
    exportFile() {
      exportCheckFile(this.userCheckList, this.fileName);
    },
    // handleSizeChange(newSize) {
    //   this.queryInfo.pagesize = newSize;
    //   this.getUserCheckList();
    // },
    // handleCurrentChange(newPage) {
    //   this.queryInfo.pagenum = newPage;
    //   this.getUserCheckList();
    // },
    // 获取用户列表
    async getUserCheckList() {
      const { data: res } = await this.$http.get(
        "check/getSignDetails/" + this.signId
      );
      console.log(res, this.signId);
      if (res.code != 200) {
        return this.$message.error("获取用户列表失败！");
      }
      // 用户列表
      this.userCheckList = res.data;
      console.log(this.userCheckList);
      this.userCheckList.forEach(item => {
        if (item.userVo.userIdentity === 0) item.userVo.userIdentity = "待填写";
        else if (item.userVo.userIdentity === 1)
          item.userVo.userIdentity = "正式党员";
        else if (item.userVo.userIdentity === 2)
          item.userVo.userIdentity = "预备党员";
        else if (item.userVo.userIdentity === 3)
          item.userVo.userIdentity = "发展对象";
        else if (item.userVo.userIdentity === 4)
          item.userVo.userIdentity = "积极分子";
        else if (item.userVo.userIdentity === 5)
          item.userVo.userIdentity = "共青团员";
        else if (item.userVo.userIdentity === 6)
          item.userVo.userIdentity = "群众";
        // 修改签到时间格式
        let strs = item.checkTime.split("T");
        item.checkTime = strs[0] + " " + strs[1];
      });
    },
    // 关闭对话框清空表单
    closeAddForm() {
      this.$refs.ruleForm.resetFields();
      this.getUserCheckList();
    },
    // 关闭编辑信息对话框
    closeEditForm() {
      this.$refs.editForm.resetFields();
      this.getUserCheckList();
    },
    // 打开修改用户信息对话框
    async showEditDialog(scoreInfo) {
      this.editForm = scoreInfo;
      console.log(this.editForm);
      this.editVisible = true;
    },
    // 修改用户成绩
    editScore() {
      this.$refs.editForm.validate(async value => {
        if (!value) return;
        console.log(this.editForm);
        const { data: res } = await this.$http.post(
          `testScore/modifyUserScore/${this.testId}/${userId}/${this.editForm.score}`
        );
        console.log(res);
        if (res.code !== 200) {
          this.$message.error("更新用户成绩失败！");
        }
        this.getUserCheckList();
        this.$message.success("更新成绩成功！");
        this.editVisible = false;
      });
    }
  }
};
</script>

<style lang="less" scoped>
.el-table {
  margin-top: 20px;
}
.el-pagination {
  margin-top: 20px;
}
</style>